import req from '@/common/request.js'


/**
 * @param {File} path 图片文件
 */
export const uploadToOSS = async path => {
	// #ifndef H5
	path = await new Promise((resolve, reject) => {
		uni.compressImage({
			src: path,
			quality: 50,
			success: resolve,
			fail: reject,
		})
	}).then((res) => {
		return res.tempFilePath
	});
	// #endif

	return req.upload("/api/upload",path ).then(res => JSON.parse(res.data))
}
